home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 46 / Amiga Format CD46 (1999-10-20)(Future Publishing)(GB)[!][issue 1999-12].iso / -in_the_mag- / reader_requests / scilab / demos / npend / macros.sci < prev    next >
Text File  |  1999-09-16  |  2KB  |  84 lines

  1. //[n]=np()
  2. // Return the size  of the Fortran pendulum 
  3. n=1;
  4. n=fort('np',n,1,'i','sort',1);
  5. //end
  6.  
  7. //[ydot]=npend ( t, th)
  8. // Fortran version 
  9. //      data r  / 1.0, 1.0, 1.0, 1.0 /
  10. //      data m  / 1.0, 1.0, 1.0, 1.0 /
  11. //      data j  / 0.3, 0.3, 0.3, 0.3 /
  12. ydot=ones(6,1)
  13. ydot=fort('npend',3,1,'i',t,2,'d',th,3,'d',ydot,4,'d','sort',4);
  14. //end
  15.  
  16. //[E]=ener( th)
  17. E=0.0;
  18. E=fort('ener',th,1,'d',E,2,'d','sort',2);
  19. //end
  20.  
  21. //[ydot]=npend3 ( t, th)
  22. // Scilab version of the three link pendulum 
  23. n=3
  24.       t1 = -th(3)
  25.       t7 = 2*r(1)*m(3)*r(3)*cos(th(1)+t1)
  26.       t16 = 2*cos(th(1)-th(2))*r(1)*r(2)*(m(2)+2*m(3))
  27.       t17 = r(3)**2
  28.       t25 = 2*r(2)*m(3)*r(3)*cos(th(2)+t1)
  29.       t26 = r(2)**2
  30.       t31 = r(1)**2
  31.       ME3S(1,3) = t7
  32.       ME3S(2,1) = t16
  33.       ME3S(1,2) = t16
  34.       ME3S(3,3) = m(3)*t17+J(3)
  35.       ME3S(3,2) = t25
  36.       ME3S(3,1) = t7
  37.       ME3S(2,2) = 4*t26*m(3)+m(2)*t26+J(2)
  38.       ME3S(1,1) = J(1)+m(1)*t31+4*t31*m(2)+4*t31*m(3)
  39.       ME3S(2,3) = t25
  40.       t1 = -th(3)
  41.       t6 = r(1)*m(3)*r(3)*sin(th(1)+t1)
  42.       t15 = r(1)*r(2)*sin(th(1)-th(2))*(m(2)+2*m(3))
  43.       t22 = r(2)*m(3)*r(3)*sin(th(2)+t1)
  44.       CC3S(1,3) = 2*t6
  45.       CC3S(2,1) = -2*t15
  46.       CC3S(1,2) = 2*t15
  47.       CC3S(3,3) = 0
  48.       CC3S(3,2) = -2*t22
  49.       CC3S(3,1) = -2*t6
  50.       CC3S(2,2) = 0
  51.       CC3S(1,1) = 0
  52.       CC3S(2,3) = 2*t22
  53.       t1 = cos(th(2))
  54.       t5 = m(3)*g
  55.       t14 = cos(th(1))
  56.       Const(2,1) = m(2)*g*r(2)*t1+2*r(2)*t1*t5
  57.       Const(3,1) = m(3)*g*r(3)*cos(th(3))
  58.       Const(1,1) = 2*r(1)*t14*m(2)*g+2*r(1)*t14*t5+m(1)*g*r(1)*t14
  59.  
  60.   ydot(1:n,1)=th((n+1):2*n)
  61.   const= const+ cc3S*( th((n+1):2*n,1).* th((n+1):2*n,1));
  62.   ydot((n+1):2*n,1)= -me3s\const
  63. //end
  64.  
  65.   
  66. //[E]=ener3(yt)
  67. // Scilab version for th three link pendulum 
  68. th=yt(1:n);
  69. thd=yt((n+1):2*n);
  70.       t1 = r(1)**2
  71.       t2 = sin(th(1))
  72.       t3 = t2**2
  73.       t4 = thd(1)**2
  74.       t7 = cos(th(1))
  75.       t8 = t7**2
  76.       t16 = r(1)*t2
  77.       t22 = sin(th(2))
  78.       t27 = (-2*r(1)*t2*thd(1)-r(2)*t22*thd(2))**2
  79.       t35 = (2*r(1)*t7*thd(1)+r(2)*cos(th(2))*thd(2))**2
  80.       t39 = thd(2)**2
  81.       E= m(1)*(t1*t3*t4+t1*t8*t4)/2+J(1)*t4/2+m(1)*g*t16+m(2)*(t27+t3...
  82.      5)/2+J(2)*t39/2+m(2)*g*(2*t16+r(2)*t22)
  83. //end
  84.